package com.lagou;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * 接收到的map输出的kv: key为从文本读入的经排序分组后的数字
 * 输出的kv: key为数字的排序序号；value为数字
 * @author lxh
 * @date 2021/3/2
 */
public class SortNumberReducer extends Reducer<LongWritable, NullWritable, LongWritable, LongWritable> {
    //排序序号，默认起点为1
    private static Long sortNum = 1L;
    private LongWritable sortNumWritable = new LongWritable();
    @Override
    protected void reduce(LongWritable key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {
        for (NullWritable value : values) {
            //封装排序序号
            sortNumWritable.set(sortNum);
            context.write(sortNumWritable,key);
            sortNum++;
        }
    }
}
